import java.util.ArrayList;
import java.util.List;
import java.util.Random;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: mirac
 * Date: 2025-08-01
 * Time: 19:20
 */
public class CardDemo {
    public static final String[] SUITS = {"♠","♥","♣","♦"};
    //制作一副牌
    private static final List<Card> buyDeck() {
        List<Card> deck = new ArrayList<>(52);
        for (int i = 0; i < 4; i++) {
            for (int j = 1; j <= 13; j++) {
                String suit = SUITS[i];
                int rank = j;
                Card card = new Card(rank,suit);
                deck.add(card);
            }
        }
        return deck;
    }

    //洗牌
    private static void swap(List<Card> deck,int i,int j) {
        Card t = deck.get(i);
        deck.set(i,deck.get(j));
        deck.set(j,t);
    }
    private static void shuffle(List<Card> deck) {
        Random random = new Random();
        for (int i = deck.size() - 1; i > 0; i--) {
            int r = random.nextInt(i);
            swap(deck,i,r);
        }
    }
    //测试
    public static void main(String[] args) {
        List<Card> deck = buyDeck();
        System.out.println("牌原本的摸样：");
        System.out.println(deck);
        shuffle(deck);
        System.out.println("洗牌后：");
        System.out.println(deck);
        //游戏开始
        //三个人，每个人轮流摸5张牌
        List<List<Card>> hands = new ArrayList<>();
        hands.add(new ArrayList<>());
        hands.add(new ArrayList<>());
        hands.add(new ArrayList<>());

        for (int i = 0; i < 5; i++) {
            for (int j = 0; j < 3; j++) {
                hands.get(j).add(deck.remove(0));
            }
        }

        System.out.println("1号玩家手中的牌：");
        System.out.println(hands.get(0));
        System.out.println("2号玩家手中的牌：");
        System.out.println(hands.get(1));
        System.out.println("3号玩家手中的牌：");
        System.out.println(hands.get(2));
    }
}
